function getStyle(el,property){
	//IE8以前不支持getComputedStyle,但存在currentStyle可供查询
	if(getComputedStyle){
		return(getComputedStyle(el)[property])
	}else{
		return el.currentStyle[property];
	}
}

//参数设为对象，以达到可同时设置多个键值对
function animate(el,properties){
	//重复调用animate会设定多个setInterval操作同一元素，元素运动速度加快，
	//所以要将setInterval设置在目标元素的某一属性上，并且每次调用animate时清除原有的setInterval
	clearInterval(el.timerId);
	el.timerId = setInterval(function(){
		
		for (var property in properties){
			var current;
			var target = properties[property];
			if (property === "opacity"){
				//opacity是小数，要用parseFloat。通过扩大百倍之后方便计算速度。Math.round四舍五入
				current = Math.round(parseFloat(getStyle(el,"opacity")) * 100) || 0;
			}else{
				current = parseInt(getStyle(el,property));
			}
			
			//以下，达到div接近目标逐渐减速，且/30保证div不会瞬间达到目标
			var speed = (target - current) / 20;
			
			speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
			if(property === "opacity"){
				el.style.opacity = (current + speed) / 100;
			}else{
				el.style[property] = current + speed + "px";
			}
		}
	},20)
}